<?php

function get_orderby($defaultValue = "")
{
    global $logger ;
    $name = "grid_order_by";
    $last = $defaultValue;
    $current = get($name);
    $sessionOrder = get_page_session($name, "");

    if(empty($sessionOrder)){
        if(!empty($current)){
            set_page_session($name, $current);
            $last = $current ;
        }
    }else{
        $desc = $current . " desc";
        if ($sessionOrder === $desc) {
            set_page_session($name, $current);
            $last = $current;
        } else if ($sessionOrder === $current) {
            set_page_session($name, $desc);
            $last = $desc;
        } else {
            if ($current != "") {
                $last = $current;
                set_page_session($name, $current);
            } else {
                $last = $sessionOrder;
            }
        }
    }

    $result = str_replace("__", ".", $last);
    return $result;
}

function get_focus_id($grid, $column)
{
    global $focusId;
    $size = $grid->fetch_rows();
    if ($size <= 0) {
        return "";
    }
    for ($i = 0; $i < $size; $i++) {
        $id = $grid->get($i, $column);
        if ($id . "" === $focusId . "") {
            return $focusId;
        }
    }
    return $grid->get(0, $column);
}

if (isset($_REQUEST["grid_reset_all"])) {
    $focusId = "";
    p5\objects\SessionUtils::clear_page_session();
    // echo  p5\objects\SessionUtils::get_page_parameter_session_key_name();
    // phpinfo();
}

$rowint = 0;
$tempFocusId = null;
$focusId = deep_get("grid_focusid", true, "");
// print_html($focusId);
$page_no = deep_get("grid_page_no", true, 0, "int");
$page_size = 8;


if (isset($_REQUEST["grid_page_no"])) {
    $focusId = "";
    set_page_session("grid_focusid", "");
}
if (isset($_REQUEST["grid_find"]) || isset($_POST["grid_find"])) {
    $focusId = "";
    set_page_session("grid_focusid", "");
    $page_no = 0;
    set_page_session("grid_page_no", 0);
}


